using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web;

using Common;

namespace data
{
    public class advertLibs
    {
        public static string lastErrorMessage = "";
        public static advertDataSetTableAdapters.tm_advertTableAdapter advertTA = new data.advertDataSetTableAdapters.tm_advertTableAdapter();
        public static advertDataSetTableAdapters.tm_small_advertTableAdapter smallAdvertTA = new data.advertDataSetTableAdapters.tm_small_advertTableAdapter();
        public static advertDataSetTableAdapters.tm_advert_locationTableAdapter advertLocationTA = new data.advertDataSetTableAdapters.tm_advert_locationTableAdapter();
        
        public static advertDataSet.tm_advertRow GetData(int advertId)
        {
            advertDataSet.tm_advertDataTable advertTbl = new advertDataSet.tm_advertDataTable();
            advertDataSet.tm_advertRow advertRow;
            advertRow = null;
            try
            {
                advertTA.FillByAdvertId(advertTbl, advertId);
                if (advertTbl.Count < 0) return null;
                advertRow = advertTbl[0];
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.Message.ToString();
            }
            return advertRow;
        }
        public static advertDataSet.tm_advert_locationDataTable GetAdvertWebpage(int advertId)
        {
            advertDataSet.tm_advert_locationDataTable advertLocationTbl = new advertDataSet.tm_advert_locationDataTable();
            try
            {
                advertLocationTA.FillByAdvertId(advertLocationTbl, advertId);
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.Message.ToString();
            }
            return advertLocationTbl;
        }

        public static data.advertDataSet.tm_small_advertRow GetSmallAdData(int smallAdsId)
        {
            try
            {
                lastErrorMessage = "";
                advertDataSet.tm_small_advertDataTable smallAdvTbl = new advertDataSet.tm_small_advertDataTable();
                smallAdvertTA.FillByAdvertId(smallAdvTbl, smallAdsId);
                if (smallAdvTbl.Count > 0) return smallAdvTbl[0];
            }
            catch (Exception exc)
            {
                lastErrorMessage = exc.Message.ToString();
            }
            return null;
        }

        public static int TotalOpenSmallAdvert(int userId)
        {
            try
            {
                advertDataSetTableAdapters.query_smallAdvTableAdapter queryTA = new data.advertDataSetTableAdapters.query_smallAdvTableAdapter();
                lastErrorMessage = "";
                return (int)queryTA.TotalOpenSmallAdvs(userId);
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.ToString();
            }
            return -1;
        }
      }
}
